package com.NeuglsWorkStudio.UI
{
	import com.NeuglsWorkStudio.Colors.HSL;
	import com.NeuglsWorkStudio.Colors.RGB;
	import com.NeuglsWorkStudio.Utility.Utility;
	
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	/**
	 * This is a tool bar which has gradient color
	 * <li>modify  Neugls at 6/2/2011 15:39</li>
	 * <p>add round rect support</p>
	 * <li>modify  ZhongKeYong</li>
	 * <li>modified 5/31/2011</li>
	 * <br/>version 2
	 * @author Neugls
	 * */	
	public class GradientBar extends Sprite
	{
		private var _FBaseColor:int;
		private var _FWidth:Number;
		private var _FHeight:Number;
		private var _FIsRound:Boolean=false;
		private var _FRoundRadius:Number;
		private var _FBottomNeedHightLight:Boolean=false;
		private var _FRoundTriangle:Array=[true,true,true,true];
		private var _FPartHightLight:Boolean=true;
		
		/**
		 * Create a gradient bar, which can be used for kinds of purpose
		 * @param BaseColor The color of the bar
		 * @param AWidth The width of the bar
		 * @param AHeight The height of the bar
		 * @param AIsRound Indicate the bar should be rounded, its value may be <code>true</code> or <code>false</code>
		 * @param ARoundRadius The radius of the round triangle
		 * @param ARoundTriangle An array indicate which triangle of the bar should be rounded, it is an array of boolean
		 *  true indicate the triangle should be rounded, false not. If the array is null, then all would be rounded.
		 * @param BottomNeedHightLight Indicated the bottom of the bar should be high lighted.
		 * */
		public function GradientBar(BaseColor:int,AWidth:Number,AHeight:Number=45,AIsRound:Boolean=false,ARoundRadius:Number=10,
				ARoundTriangle:Array=null,BottomNeedHightLight:Boolean=false,PartHightLight:Boolean=true)
		{
			super();
			
			_FBaseColor=BaseColor;
			_FWidth=AWidth;
			_FHeight=AHeight;
			_FIsRound=AIsRound;
			_FRoundRadius=ARoundRadius;
			_FRoundTriangle=ARoundTriangle;
			_FBottomNeedHightLight=BottomNeedHightLight;
			_FPartHightLight=PartHightLight;
			Paint();
		}
		
		public function get RoundRadius():Number
		{
			return _FRoundRadius;
		}

		public function set RoundRadius(value:Number):void
		{
			_FRoundRadius = value;
			Paint();
		}

		/**indicated this bar is round or not**/
		public function get IsRound():Boolean
		{
			return _FIsRound;
		}

		/**
		 * @private
		 */
		public function set IsRound(value:Boolean):void
		{
			_FIsRound = value;
			Paint();
		}

		public function get Height():Number
		{
			return _FHeight;
		}

		public function set Height(value:Number):void
		{
			_FHeight = value;
		}

		public function get Width():Number
		{
			return _FWidth;
		}

		public function set Width(value:Number):void
		{
			_FWidth = value;
		}

		public function get BaseColor():int
		{
			return _FBaseColor;
		}

		public function set BaseColor(value:int):void
		{
			_FBaseColor = value;
			Paint();
		}
		
		
		
		protected function Paint():void{
			var bitmapData:BitmapData=Utility.CreateGradientBitmapData(_FWidth,
				_FHeight,_FBaseColor,_FBottomNeedHightLight,_FPartHightLight);
				
			
			this.graphics.clear();
			this.graphics.beginBitmapFill(bitmapData,null,false,true);
			
			//Modified by ZhongKeYong 5/31/2011
			//added round rect
			if(_FIsRound){
				if(this._FRoundTriangle==null){
					this.graphics.drawRoundRect(0,0,_FWidth,_FHeight,_FRoundRadius*2,_FRoundRadius*2);
				}else{
					this.graphics.drawRoundRectComplex(0,0,_FWidth,_FHeight,_FRoundTriangle[0]*_FRoundRadius,
						_FRoundTriangle[1]*_FRoundRadius,_FRoundTriangle[2]*_FRoundRadius,_FRoundTriangle[3]*_FRoundRadius);
				}
			}else{
				this.graphics.drawRect(0,0,_FWidth,_FHeight);
			}
			
			this.graphics.endFill();
		}
		
		public function Resize():void{
			Paint();
		}
	}
}